package com.link.base.base.applyqualityinfor.controller;

import com.link.base.base.applyquality.model.ApplyQuality;
import com.link.base.base.applyqualityinfor.model.ApplyQualityInfor;
import com.link.base.base.applyqualityinfor.service.ApplyQualityInforService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liushoulong
 * @date 2018-11-08
 * @desc 酒体质检报告申请-产品信息
 */
@Controller("ApplyQualityInforController")
@RequestMapping("/link/applyQualityInfor")
public class ApplyQualityInforController extends BasicController<ApplyQualityInfor> {

    @Resource
    private ApplyQualityInforService applyQualityInforService;

    @Override
    public BasicService<ApplyQualityInfor> getBasicService() throws Exception {
        return applyQualityInforService;
    }

    /**
     * 根据申请查询对应产品列表
     *
     * @param applyQuality
     * @param qps
     * @return
     */
    @RequestMapping("/queryByApplyId")
    @ResponseBody
    public Map<String, Object> queryByApplyId(@JsonParam ApplyQuality applyQuality, @JsonParam QueryParams qps) {

        Map<String, Object> result = new HashMap<String, Object>(8);
        try {
            ApplyQuality applyQuality1 = (ApplyQuality) BasicModel.transformClass(applyQuality, qps);
            List<ApplyQualityInfor> applyQualityInforList = applyQualityInforService.queryByApplyId(applyQuality1);
            result.put("success", true);
            result.put("rows", applyQualityInforList);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("rows", new ArrayList<ApplyQualityInfor>());
        }
        return result;
    }

}
